
import { createInStockAccout } from '@/content-scripts/components/trading/spotAccount/index.js'

let spotTableObervers = null

export function spotTableSearch() {
    if (spotTableObervers) spotTableObervers.disconnect();

    let previousValues = {
        searchValue: null,
        isHiddenValue: null
    };
    spotTableObervers = new MutationObserver(() => {
        // const tabBtn = document.querySelector('.mantine-ujq11l > .mantine-q2zxwr[data-active="true"]')
        // const tabsInnerHTML = tabBtn.querySelector('.mantine-1d51fly').innerHTML
        // console.log(tabsInnerHTML, 'changeBtnchangeBtnchangeBtnchangeBtnchangeBtn');
        // const hasChanged = tabsInnerHTML !== previousValues.firstStageTabs
        const searchInput = document.querySelector('.dataTables_wrapper > .top > .dataTables_filter > label > input[placeholder="搜索"]')

        const isHiddenRadio = document.querySelector('.flex-items-center > .HideZeroDiv > label > input')

        const hasChanged =
            searchInput.value !== previousValues.searchValue ||
            isHiddenRadio.classList.value !== previousValues.isHiddenValue

        if (searchInput && isHiddenRadio && hasChanged) {
            previousValues = {
                searchValue: searchInput.value,
                isHiddenValue: isHiddenRadio.classList.value
            }
            createInStockAccout()
        }

    });
    spotTableObervers.observe(document.body, {
        childList: true,
        subtree: true,
        attributes: true,
        characterData: true,
    });
}